/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ui.user.staff;

import hibernate.dao.CenterDAO;
import hibernate.entity.Centers;
import hibernate.entity.Courses;
import hibernate.entity.Staffs;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.servlet.http.HttpSession;
import ui.common.AbstractUIBean;
import util.Converter;

/**
 *
 * @author Neo
 */
@ManagedBean
@RequestScoped
public class StaffCourses extends AbstractUIBean {

    /**
     * Creates a new instance of StaffCourses
     */
    List<Courses> currListCourse;
    Centers center;
    List<Centers> allCenter;
    
    public List<Courses> getCurrListCourse() {
        return currListCourse;
    }
    
    public void setCurrListCourse(List<Courses> currListCourse) {
        this.currListCourse = currListCourse;
    }
    
    public Centers getCenter() {
        return center;
    }
    
    public void setCenter(Centers center) {
        this.center = center;
    }
    
    public StaffCourses() {
        HttpSession session = getHttpSession();
        Staffs s = (Staffs) session.getAttribute("currStaff");
        currListCourse = Converter.iteratorToList(s.getCourseses().iterator());
        allCenter = new CenterDAO().readAll();
    }
    
    public void selectCenter() {
        currListCourse = new ArrayList<Courses>();
        HttpSession session = getHttpSession();
        Staffs s = (Staffs) session.getAttribute("currStaff");
        for (Courses courses : s.getCourseses()) {
            if (courses.getCenters() == center) {
                currListCourse.add(courses);
            }
        }
    }
    
    public List<Centers> getAllCenter() {
        return allCenter;
    }
    
}
